class code3 {
    public boolean isValid(String s) {
        Stack<Character> st = new Stack<>();
        HashMap<Character,Character> map = new HashMap<>();
        map.put(']','[');
        map.put(')','(');
        map.put('}','{');
        char[] ss = s.toCharArray();
        for(char c:ss) {
            if(c=='('||c=='['||c=='{') {
                st.push(c);
            } else {
                if(st.isEmpty() || st.pop()!=map.get(c)) {
                    return false;
                }
            }
        }
        return st.isEmpty();
    }
}